package work20241220;

import java.io.*;

/**
 * @author zdl
 * @date 2024/12/20
 */
public class Demo1 {
    public static void main(String[] args) throws IOException {
        copyIMG(); //默认
        copyIMG1(); //自定义缓存
        copyIMG2(); //无缓存
    }

    //默认 缓存
    public static void copyIMG() throws IOException{
        long l = System.currentTimeMillis();
        FileInputStream fis  = new FileInputStream("D:/test/MIUI12.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos  = new FileOutputStream("D:/test/a/2.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int length;
        while ((length = bis.read()) != -1){
            bos.write(length);
        }
        fos.close();
        fis.close();
        long e = System.currentTimeMillis();
        System.out.println(e - l);
    }

    //自定义 缓存
    public static void copyIMG1() throws IOException{
        long l = System.currentTimeMillis();
        FileInputStream fis  = new FileInputStream("D:/test/MIUI12.jpg");
        BufferedInputStream bis = new BufferedInputStream(fis);
        FileOutputStream fos  = new FileOutputStream("D:/test/a/2.jpg");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] bty = new byte[8 * 1024];
        int length;
        while ((length = bis.read()) != -1){
            bos.write(bty,0,length);
        }
        fos.close();
        fis.close();
        long e = System.currentTimeMillis();
        System.out.println(e - l);
    }
    public static void copyIMG2() throws IOException{
        long l = System.currentTimeMillis();
        FileInputStream fis = new FileInputStream("D:/test/MIUI12.jpg");
        FileOutputStream fos = new FileOutputStream("D:/test/a/2.jpg");
        int len;
        while ((len = fis.read())!=-1){
            fos.write(len);
        }
        long e = System.currentTimeMillis();
        System.out.println(e - l);
    }
}
